import { useRequest } from "ahooks";
import { request } from "@/utils/request";

import { LoginDataType } from "@/types/login";

export const login = async (data: LoginDataType) => {
  try {
    const response = await request("/v1/admin/login", {
      method: "POST",
      body: JSON.stringify(data),
    });
    return response;
  } catch (error) {
    return error;
  }
};

export const useLogin = () => {
  return useRequest(login, {
    manual: true,
  });
};
